In [1]:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
from __future__ import division
from itertools import product
from spacetime.CA_Simulators.Greenberg_Hastings import *

Example code for using Greenberg-Hastings CA module

See documenation in Greenberg_Hastings.py for details on the Greenberg-Hastings model.


In [ ]:

Classic spiral wave behavior


In [2]:
#Set model parameters

#square neighborhood radius
R = 3
#number of states / colors
K = 8
#excitation threshhold
T = 6

#initial conditions on 300x300 lattice
initial = random_state_v2((300,300), K, 2.0/9)

#initialize CA object with chosen parameters and initial condition
spirals = greenberg_hastings(initial, R, K, T)
#evolve the CA for 300 time steps
spirals.evolve(300)

Animate the spacetime field produced by the above code


In [3]:
spacetime_animation(spirals.get_spacetime(), colors = plt.cm.rainbow)

In [ ]:

You can also animate on the fly using the .animate() method. We run the same code again, but use .animate(duration = 300) instead of .evolve(300). Both methods produce a 300x300x300 spacetime field that can be visualized with spacetime_animation.


In [5]:
#Set model parameters

#square neighborhood radius
R = 3
#number of states / colors
K = 8
#excitation threshhold
T = 6

#initial conditions on 300x300 lattice
initial = random_state_v2((300,300), K, 2.0/9)

#initialize CA object with chosen parameters and initial condition
spirals = greenberg_hastings(initial, R, K, T)
#evolve the CA for 300 time steps
spirals.animate(time = 300)

Again we can still use spacetime_animation, this time if we want to watch that specific evolution again. Since the .animate() method animates on the fly, it is typically slower.


In [6]:
spacetime_animation(spirals.get_spacetime(), colors = plt.cm.rainbow)

In [ ]:


In [ ]:

Some phenomonolgy: exploring parameter space and adding stochastic driving

Some fun travelling particles and collisions


In [7]:
R = 1
K = 4
T = 2
initial = random_state_v1((250, 250), 0.2)
example1 = greenberg_hastings(initial, R, K, T)

In [8]:
example1.evolve(300)

In [9]:
spacetime_animation(example1.get_spacetime(), colors = plt.cm.rainbow)

In [ ]:


In [ ]:

Global oscillations induced by stochastic driving

Start with very low driving, just see random sprinkling of excitations, no oscillations

Driving strength: 0.02


In [10]:
R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example2 = greenberg_hastings(initial, R, K, T)

In [11]:
example2.drive(200, 0.02)

In [12]:
spacetime_animation(example2.get_spacetime(), colors = plt.cm.rainbow)

In [ ]:

Keep same model parameters and initial conditions, now just bump up the driving rate and see global oscillations

Driving strength: 0.1


In [13]:
R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example3 = greenberg_hastings(initial, R, K, T)

In [14]:
example3.drive(200, 0.1)

In [15]:
spacetime_animation(example3.get_spacetime(), colors = plt.cm.rainbow, interval = 5)

In [ ]:

Increase driving further, collective oscillations become more pronounced

Driving strength: 0.5


In [16]:
R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example4 = greenberg_hastings(initial, R, K, T)

In [17]:
example4.drive(300, 0.5)

In [18]:
spacetime_animation(example4.get_spacetime(), colors = plt.cm.rainbow, interval = 5)

In [ ]:


In [ ]: